<template>
    <z-modal
      v-bind="modalOption"
      @ok="handleOk"
      @cancel="handleCancel"
      cancelText="关闭"
    >
      <a-spin :spinning="confirmLoading">
        <a-form-model layout="horizontal" labelAlign="right" ref="ruleForm" :label-col="labelCol" :wrapper-col="wrapperCol" :model="form" :rules="validatorRules">
          <a-row>
            <a-col :span="12" >
              <a-form-model-item label="分解来源" prop = "source" >
                <a-input v-model.trim="form.source" :disabled="disableSubmit"/>
              </a-form-model-item>
            </a-col>
            <a-col :span="12" >
              <a-form-model-item label="工作大类" prop="category">
                <a-input v-model.trim="form.category" :disabled="disableSubmit"/>
              </a-form-model-item>
            </a-col>
            <a-col :span="12" >
                <a-form-model-item label="重点工作" prop = "priority" >
                    <a-input v-model.trim="form.priority" :disabled="disableSubmit"/>
                </a-form-model-item>
            </a-col>
            <a-col :span="12" >
                <a-form-model-item label="主责部门" prop = "responsibleDepts" >
                    <ZSelectDept :multiple="true" v-model.trim="form.responsibleDepts" @change="selectDept" :disabled="disableSubmit"/>
                </a-form-model-item>
            </a-col>
            <a-col :span="12" >
              <a-form-model-item label="分管领导" prop = "leaderName" >
                <a-input v-model.trim="form.leaderName" :disabled="disableSubmit"/>
              </a-form-model-item>
            </a-col>
            <a-col :span="12" >
              <a-form-model-item label="完成标志" prop = "completionMark" >
                <a-input v-model.trim="form.completionMark" :disabled="disableSubmit"/>
              </a-form-model-item>
            </a-col>
            <a-col :span="12" >
                <a-form-model-item label="起止时间" prop="startEndTime">
                    <a-range-picker format="YYYY-MM-DD" v-model.trim="form.startEndTime" style="width: 100%" :disabled="disableSubmit"/>
                </a-form-model-item>
            </a-col>
          </a-row>
        </a-form-model>
      </a-spin>
    </z-modal>
  </template>

<script>
import ModalFormMixin from '@/mixins/ModalFormMixin'
import ZSelectDept from '@/components/zzbiz/ZSelectDept'
import moment from 'moment'
export default {
  name: 'ScheduleModal',
  components: { ZSelectDept },
  mixins: [ModalFormMixin],
  data() {
    return {
      validatorRules: {
        source: [{ required: true, message: '请输入分解来源' }],
        category: [{ required: true, message: '请输入工作大类' }],
        priority: [{ required: true, message: '请输入重点工作' }],
        responsibleDepts: [{ required: true, message: '请输入主责部门' }],
        leaderName: [{ required: true, message: '请输入分管领导' }],
        completionMark: [{ required: true, message: '请输入完成标志' }],
        startEndTime: [{ required: true, message: '请输入起止时间' }]
      },
      url: {
        add: '/plan/schedule/v1/add',
        edit: '/plan/schedule/v1/edit'
      }
    }
  },
  methods: {
    selectDept(codes, selectRow) {
      this.form.deptIds = selectRow.map(item => item.id)
    },
    classifyIntoFormData() {
      // eslint-disable-next-line no-unused-vars
      const { startEndTime, responsibleDepts, ...rest } = this.form
      return {
        ...rest,
        planYear: moment().year(),
        startTime: moment.isMoment(startEndTime[0]) ? startEndTime[0].format('YYYY-MM-DD') : startEndTime[0],
        endTime: moment.isMoment(startEndTime[1]) ? startEndTime[1].format('YYYY-MM-DD') : startEndTime[1]
      }
    }
  }
}
</script>

